package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.InspectCallPolicEquipment;
import com.ruoyi.system.mapper.InspectCallPolicEquipmentMapper;
import com.ruoyi.system.service.InspectCallPolicEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (InspectCallPolicEquipment)表服务实现类
 *
 * @author makejava
 * @since 2022-11-15 13:32:10
 */
@Service
public class InspectCallPolicEquipmentServiceImpl implements InspectCallPolicEquipmentService {
    @Autowired
    private InspectCallPolicEquipmentMapper inspectCallPolicEquipmentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public InspectCallPolicEquipment queryById(Integer id) {
        return this.inspectCallPolicEquipmentDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param inspectCallPolicEquipment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<InspectCallPolicEquipment> queryByPage(InspectCallPolicEquipment inspectCallPolicEquipment, PageRequest pageRequest) {
        long total = this.inspectCallPolicEquipmentDao.count(inspectCallPolicEquipment);
        return new PageImpl<>(this.inspectCallPolicEquipmentDao.queryAllByLimit(inspectCallPolicEquipment, pageRequest), pageRequest, total);
    }

    @Override
    public List<InspectCallPolicEquipment> queryAll(InspectCallPolicEquipment inspectCallPolicEquipment) {
        return inspectCallPolicEquipmentDao.queryAll(inspectCallPolicEquipment);
    }

    /**
     * 新增数据
     *
     * @param inspectCallPolicEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public InspectCallPolicEquipment insert(InspectCallPolicEquipment inspectCallPolicEquipment) {
        this.inspectCallPolicEquipmentDao.insert(inspectCallPolicEquipment);
        return inspectCallPolicEquipment;
    }

    /**
     * 修改数据
     *
     * @param inspectCallPolicEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public InspectCallPolicEquipment update(InspectCallPolicEquipment inspectCallPolicEquipment) {
        this.inspectCallPolicEquipmentDao.update(inspectCallPolicEquipment);
        return this.queryById(inspectCallPolicEquipment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.inspectCallPolicEquipmentDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<InspectCallPolicEquipment> inspectCallPolicEquipments, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(inspectCallPolicEquipments) || inspectCallPolicEquipments.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        inspectCallPolicEquipmentDao.insertBatch(inspectCallPolicEquipments);
        return "成功";
    }
}
